<template>
  <div style="padding: 10px; width: 100%">
    <div style="margin: 10px 0">
      <el-input
        placeholder="请输入考试名称"
        v-model="search"
        style="width: 200px"
      >
        <template #append>
          <el-button icon="el-icon-search" @click="load"></el-button>
        </template>
      </el-input>
    </div>
    <el-table :data="tableData" border stripe style="width: 99%" height="76vh">
      <el-table-column type="selection" width="55" />
      <el-table-column prop="id" label="ID" />
      <el-table-column prop="name" label="考试名称" />
      <el-table-column prop="time" label="考试时间" />
      <el-table-column prop="type" label="考试类型"> </el-table-column>
      <el-table-column prop="gradeName" label="考试年级" />
      <el-table-column prop="remark" label="备注" />
     


      <el-table-column label="操作" width="160px">
        <template #default="scope">
          <el-button
            @click="handleEdit(scope.row)"
            size="mini"
            type="primary"
            plain
            >查看成绩</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div style="margin: 10px 0">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import request from "../../utils/request";
export default {
  name: "List",
  data() {
    return {
      //当前页
      currentPage: 1,
      pageSize: 10,
      total: 0,
      tableData: [],
      search: "",
      user:{}
    };
  },
  created() {
      let str = sessionStorage.getItem("user") || "{}"
    this.user = JSON.parse(str)
    this.load();
  },
  methods: {
    // 分页查询
    load() {
      request
        .get("/headmaster/examlist", {
          params: {
            PageNum: this.currentPage,
            PageSize: this.pageSize,
            account: this.user.account,
            name:this.search
          },
        })
        .then((res) => {
          console.log(res);
          this.tableData = res.data.records;
          this.total = res.data.total;
          console.log("=============>");
          console.log(this.tableData);
          for (let i = 0; i <= res.data.records.length; i++) {
            this.tableData[i].gradeName = res.data.records[i].gradeList.name;
            if (res.data.records[i].type == 1) {
              this.tableData[i].type = "年级考试";
            } else {
              this.tableData[i].type = "平时考试";
            }
          }
        });
    },
    //跳转成绩列表
    handleEdit(row){
      console.log("22222");
      console.log(row.name);
      this.$router.push({
        path:'/headmasterstudentscorelist',
        name:'headmasterstudentscorelist',
        query:{
          id:row.id,
          gradeId:row.gradeId,
          name:row.name
        }
      })
    },
    //改变当前每页的个数触发
    handleSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.load();
    },
    //改变当前页码触发
    handleCurrentChange(pageNum) {
      this.currentPage = pageNum;
      this.load();
    },
  },
};
</script>

<style>
.a1 {
  font-size: 12px;
  text-align: center;
  margin-left: 20px;
}
</style>
